<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <title>Design Patterns</title>
</head>
<body>
<h3>Key Patterns </h3>

<p><strong>Inversion of Control (IoC). </strong></p>

<p>The idea that an application is controlled from the top down</p>

<p><strong>Separation of Concerns (SoC) </strong></p>

<p>The idea that a class (aspect) should do one job and do it well</p>

<p><strong>Separation of API (or Interface) from Implementation</strong></p>

<p>The idea that you define and code to work interfaces</p>

<p><strong>Aspect Oriented Programming (AOP) </strong></p>

<p>Mostly lightweight nowadays where you add a chain of interceptors around a method call that can handle orthogonal
    concerns</p>

<p><strong>Component Oriented Programming (COP) </strong></p>

<p>The idea that you decompose your software into components</p>

<p><strong>Declarative Programming</strong></p>

<p>Where you use a declarative-style language (usually xml) to determine things like component wiring (i.e. your average
    tomcat config file, generalized)</p>

<p><strong>Event Based Programming (EBP) </strong></p>

<p>Basically making the inter-object method call asynchronous and encapsulating such a call into some kind of event
    object that can be queued, modified, etc</p>

<h3>More Thinking </h3>

<p><strong>Good Citizen: Least surprise, least paranoia</strong></p>

<p>Authors: Dan North, Aslak Hellesoy</p>

<p>Imagine a software system where there is no need for you to spend your time programming defensively; your objects
    will be used responsibly, and your methods will always be passed sensible arguments.</p>

<p>This low-friction utopia can be approached by establishing some simple programming rules so that every class acts as
    a 'good citizen' in the society of classes collaborating at runtime.</p>

<p>This page outlines some rules that we, and others, believe lead to good citizenship. All are aimed at improving
    clarity, reducing surprise, and promoting basic consistency.</p>

<p>As a good citizen, I...</p>
<ul>
    <li> Keep a consistent state at all times - init() or populate() is a code smell.</li>
    <li>Have no static fields or methods</li>
    <li>Never expect or return null.</li>
    <li>Fail fast - even when constructing.</li>
    <li>Am Easy to test- all dependent object I use can be passed to me, often in my constructor (typically as Mock
        Objects).
    </li>
    <li>Accept dependent object that can easily be substituted with Mock Objects (I don't use Concrete Class
        Dependency).
    </li>
    <li>Chain multiple constructors to a common place (using this(...)).</li>
    <li>Always define hashCode() alongside equals()</li>
    <li>Prefer immutable value objects that I can easily throw away.</li>
    <li>Have a special value for 'nothing' - e.g. Collections.EMPTY_SET.</li>
    <li>Raise checked exceptions when the caller asked for something unreasonable - e.g. open a non-existant file.</li>
    <li>Raise unchecked exceptions when I can't do something reasonable that the caller asked of me - e.g. disk error
        when reading from an opened file.
    </li>
    <li>Only catch exceptions that can be handled fully.</li>
    <li>Only log information that someone needs to see.</li>
</ul>
<p>Classes that are designed for <a href="injection.html">Constructor Injection</a> are better citizens than those that
    are not.</p>
</body>


</html>
